package il.ac.mta.javaweb.ex1.logic.grids;

import il.ac.mta.javaweb.ex1.logic.ShipSqaure;

import java.awt.Point;
import java.util.Hashtable;
import java.util.Set;

public abstract class GridBase
{
	public static final int ZERO = 0;
	public static final int ONE = 1;
	public static final int TWO = 2;
	public static final int THREE = 3;
	public static final int FOUR = 4;
	public static final int FIVE = 5;

	public static final int WIDTH = 10;
	public static final int HEIGHT = 10;

	protected abstract Set<Point> getSetOfPositionsOfShips();

	protected abstract Hashtable<Point, ShipSqaure> getMapOfPositionsOfShips();

	protected String[][] stringGridSquares = new String[WIDTH][HEIGHT];

	@Override
	public String toString()
	{
		String retVal = "";

		for (Point position : getSetOfPositionsOfShips())
		{
			if (getMapOfPositionsOfShips().get(position).isHit())
			{
				stringGridSquares[position.x][position.y] = "X";
			}
		}

		retVal += "   | A | B | C | D | E | F | G | H | I | J |\n";
		retVal += "---=========================================\n";

		for (int j = 0; j < stringGridSquares[0].length; ++j)
		{
			retVal += j + 1 + " ";
			if (j != 9)
			{
				retVal += " ";
			}

			retVal += "| ";

			for (int i = 0; i < stringGridSquares.length; ++i)
			{
				retVal += stringGridSquares[i][j] + " | ";
			}

			retVal += "\n---=========================================\n";
		}

		return retVal;
	}
}
